﻿/******************************************************************
* 项目名称 ：TorrentDHT 
* 项目描述 ： 
* 类 名 称 ：CustomITrackable 
* 类 描 述 ： 
* CLR 版本 ：4.0.30319.42000 
* 版权所有 ：袁振峰
* 联系方式 ：http://www.ustuy.com/ 
******************************************************************/

using MonoTorrent;
using MonoTorrent.Common;
using MonoTorrent.Tracker;

namespace SampleTracker
{
    public class CustomITrackable : ITrackable
    {
        // I just want to keep the TorrentFiles in memory when i'm tracking the torrent, so i store
        // a reference to them in the ITrackable. This allows me to display information about the
        // files in a GUI without having to keep the entire (really really large) Torrent instance in memory.
        private TorrentFile[] files;

        // We require the infohash and the name of the torrent so the tracker can work correctly
        private InfoHash infoHash;
        private string name;

        public CustomITrackable(Torrent t)
        {
            // Note: I'm just storing the files, infohash and name. A typical Torrent instance
            // is ~100kB in memory. A typical CustomITrackable will be ~100 bytes.
            files = t.Files;
            infoHash = t.InfoHash;
            name = t.Name;
        }

        /// <summary>
        /// The files in the torrent
        /// </summary>
        public TorrentFile[] Files
        {
            get { return files; }
        }

        /// <summary>
        /// The infohash of the torrent
        /// </summary>
        public InfoHash InfoHash
        {
            get { return infoHash; }
        }

        /// <summary>
        /// The name of the torrent
        /// </summary>
        public string Name
        {
            get { return name; }
        }
    }
}
